package com.example.demo.controller;


import com.example.demo.model.Administrator;
import com.example.demo.service.AdministratorService;
import com.example.demo.tools.ResponseBodyMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/administrator")
public class AdministratorController {
    // 注入 LoginService 依赖
    @Autowired
    private AdministratorService administratorService;


    @RequestMapping("/login")
    public ResponseBodyMessage<Administrator> select (@RequestParam("username") String username, @RequestParam("password") String password, HttpServletRequest request) {
        // 非空判断
        if (StringUtils.hasLength(username)&&StringUtils.hasLength(password)) {
            return administratorService.select(username, password, request);
        } else {
            // 参数错误
            return new ResponseBodyMessage<>(400, "登陆失败",null);
        }
    }
}
